package file.day9_19.day04;

import java.io.Serializable;

public class Person implements Serializable {

    //implements AutoCloseable,类实现了该接口
    //使用try-with-resources语法创建的资源抛出异常后，
    // JVM会自动调用close 方法进行资源释放
    private int age;
    public static final long UID = 2;

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws Exception {
        if(age > 100 || age <= 0){
            throw new RuntimeException("年龄不合法");
        }
        this.age = age;
    }

    public String toString() {
        return "Person{" +
                "age=" + age +
                '}';
    }
    public void close() throws Exception {
        System.out.println("good");
    }
}
